﻿/// Author : Bui Huu Loc
/// Date : 07-04-2009
using System;
using System.Xml;
using System.Data;
using System.IO;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using LibKetoan;

namespace Ketoan
{	
	public class frmReport_kp_class
	{

		#region Variable
		bool flag_dsnull;
		string sql="",sql1="",sql2="";
		DataSet ds_Data,ds_Data_;
		DataSet ds_Data2,ds_Data2_;
		DataSet ds_Data3,ds_Data3_;
		#endregion

		#region Constructor
		public frmReport_kp_class()
		{
			
		}
		#endregion	

		#region Destructor
		public void Dispose()
		{
			try
			{
				ds_Data.Dispose();
			}
			catch{};
		}
		
		#endregion

		#region Functions
		/// <summary>
		/// Tao file xml "KT_TongHopTinhHinhKP_QuyetToanKP2_.xml" cho report KT_TongHopTinhHinhKP_QuyetToanKP2_.rpt
		/// </summary>		
		public DataSet QuyetToanKP_qh(AccessData a, string s_IDlk,string s_IDChuong, string s_IDHoatdong, string s_IDNguongoc,string s_tuthang,string s_denthang,string s_yy,string s_idnhom)
		{
			#region lay cac field va noidungmuc
			sql = "SELECT id,loai,khoan,loaikhoan,tenloaikhoan,t1.muc,tm,noidungtm,noidungmuc,manguon,nhom,stk,sotien,thang,nsnn,lephidelai, ";
			sql += " vientro,nguonkhac,group1,num_group1,group2, num_group2,lk_nsnn,  lk_lephidelai,  lk_vientro, lk_nguonkhac";
			sql += " FROM";
			sql += " (SELECT DISTINCT ch.id as id,substr(trim(lk.lk),0,3) as loai,substr(trim(lk.lk),5,3) as khoan,lk.lk as loaikhoan,lk.tlk as tenloaikhoan,substr(trim(ch.mtm),0,4) ";
			sql += " as muc,substr(trim(ch.mtm),6,4) as tm, substr(trim(ng.mang),0,2) as manguon,muc.nhom as nhom,tk.stk as stk,ch.ttk as noidungtm,ctct.stien ";
			sql += " as sotien,ct.thanggs as thang, 0 as nsnn,0 as lephidelai, 0 as vientro,0 as nguonkhac,'' as group1,'' as num_group1,'' as group2,'' as ";
			sql += " num_group2 ,0 as lk_nsnn, 0 as lk_lephidelai, 0 as lk_vientro, 0 as lk_nguonkhac ";			
			sql += " FROM a_ctct" + s_yy + " ctct INNER JOIN a_dmtk tk ON tk.id=ctct.tkcoa OR tk.id=ctct.tknoa INNER JOIN a_dmch ch ON (ctct.mtmno = ch.id OR ctct.mtmco = ch.id) ";
			sql += " INNER JOIN a_dmng ng ON (substr(trim(tk.stk),7,length(ng.mang))=ng.mang) OR";
			sql += " (substr(trim(tk.stk),6,length(ng.mang))=ng.mang) LEFT JOIN a_dmlk lk ON lk.id = ctct.lk INNER JOIN a_ct" + s_yy + " ct ON ct.id = ctct.idct  LEFT JOIN";
			sql += " a_dmnhom muc ON ch.nhmuc = muc.id  LEFT JOIN a_dmchuong chuong ON chuong.id=ct.chuong  INNER JOIN a_dmnhombc bc ON bc.id = ct.idbc ";
			if (s_tuthang !="" || s_denthang!="")
				sql += " WHERE ct.thanggs BETWEEN "+ s_tuthang + " AND " + s_denthang;
			if (s_IDChuong!="") 
				sql += " AND ct.chuong=" + s_IDChuong;
			if (s_IDHoatdong!="") 
				sql += " AND ct.hoatdong=" + s_IDHoatdong;
			if (s_IDNguongoc!="") 
				sql += " AND ng.id=" + s_IDNguongoc;			
			if (s_IDlk!="") 
				sql += " AND ctct.lk=" + s_IDlk;
			if (s_idnhom!="") 
				sql += " AND ct.idbc=" + s_idnhom;
			sql += " AND (substr(trim(tk.stk),0,5)) like '66121%'" ;
			sql += " OR (substr(trim(tk.stk),0,5)) like '66122%' ";
			sql += " OR (substr(trim(tk.stk),0,4)) like '6621%'";
			sql += " OR (substr(trim(tk.stk),0,4)) like '6622%'";			
			sql += " ORDER BY tk.stk ) t1";
			sql += " INNER JOIN ";
			sql += " (SELECT ch.mtm as muc, ch.ttk as noidungmuc FROM a_dmch ch where ch.cd=3 ORDER BY ch.mtm) t2 ON t1.muc=t2.muc";
			try
			{
				ds_Data = a.get_data(sql).Copy();
				if(ds_Data.Tables[0].Rows.Count<=0)
					flag_dsnull=true;
			}
			catch
			{
				flag_dsnull = true;
			}  
			#endregion			

			#region them cot nsnn,lephidelai,vientro, nguonkhac vao dataset
			if (flag_dsnull != true)
			{				
				int countRow=ds_Data.Tables[0].Rows.Count;				
				for(int j=0;j<countRow;j++)
				{		
					try
					{
						decimal sotien = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["sotien"].ToString());
						decimal nsnn = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["nsnn"].ToString());
						decimal lephidelai = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["lephidelai"].ToString());
						decimal vientro = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["vientro"].ToString());
						decimal nguonkhac = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["nguonkhac"].ToString());
						string manguon = (ds_Data.Tables[0].Rows[j]["manguon"].ToString());

						if (manguon=="01" || manguon=="02")
						{
							nsnn += sotien;
							vientro=0;
							lephidelai=0;
							nguonkhac=0;
						}
						else if (manguon=="04")
						{	
							lephidelai +=sotien;
							vientro=0;
							nsnn=0;
							nguonkhac=0;
						}
						else if (manguon=="03")
						{
							lephidelai =0;
							vientro += sotien;
							nsnn=0;
							nguonkhac=0;
						}
						else
						{
							lephidelai =0;
							vientro = 0;
							nsnn=0;
							nguonkhac+=sotien;
						}
				
						ds_Data.Tables[0].Rows[j]["nsnn"] = nsnn;	
						ds_Data.Tables[0].Rows[j]["lephidelai"] = lephidelai;	
						ds_Data.Tables[0].Rows[j]["vientro"] = vientro;	
						ds_Data.Tables[0].Rows[j]["nguonkhac"] = nguonkhac;						
					}
					catch (Exception Ex)
					{
						MessageBox.Show("Error : " + Ex ,"Thông báo !");
					}		
				}
			}
			ds_Data.AcceptChanges();
			#endregion												
			
			#region tao cac cot de group theo loai khoan 			
			if (flag_dsnull != true)
			{				
				int countRow1=ds_Data.Tables[0].Rows.Count;
				for(int j=0;j<countRow1;j++)
				{
					try
					{
						string group1 = (ds_Data.Tables[0].Rows[j]["group1"].ToString());
						string num_group1 = (ds_Data.Tables[0].Rows[j]["num_group1"].ToString());
						string group2 = (ds_Data.Tables[0].Rows[j]["group2"].ToString());
						string num_group2 = (ds_Data.Tables[0].Rows[j]["num_group2"].ToString());
						string stk = ((ds_Data.Tables[0].Rows[j]["stk"].ToString())).Trim().Split('.')[0].ToString();
						if (stk.StartsWith("661"))
						{
							group1="I - CHI HOẠT ĐỘNG";
							num_group1="1";
							if (stk.StartsWith("66121"))
							{
								group2="1. CHI THƯỜNG XUYÊN";
								num_group2="1.1";
							}
							if (stk.StartsWith("66122"))
							{
								group2="2. CHI KHÔNG THƯỜNG XUYÊN";
								num_group2="1.1";
							}
						}
						if (stk.StartsWith("662"))
						{
							group1="II - CHI DỰ ÁN";
							num_group1="2";
							if (stk.StartsWith("6621"))
							{
								group2="1. CHI QUẢN LÝ DỰ ÁN";
								num_group2="2.1";
							}
							if (stk.StartsWith("6622"))
							{
								group2="2. CHI THỰC HIỆN DỰ ÁN";
								num_group2="2.2";
							}
						}
						ds_Data.Tables[0].Rows[j]["group1"] = group1;
						ds_Data.Tables[0].Rows[j]["num_group1"] = num_group1;
						ds_Data.Tables[0].Rows[j]["group2"] = group2;
						ds_Data.Tables[0].Rows[j]["num_group2"] = num_group2;
						
					}
					catch (Exception Ex)
					{
						MessageBox.Show("Error : " + Ex ,"Thông báo !");
					}				
				}
			}
			ds_Data.AcceptChanges();
			#endregion
					
			if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
			ds_Data.WriteXml("..\\xml\\KT_TongHopTinhHinhKP_QuyetToanKP2_.xml",XmlWriteMode.WriteSchema);
			if (flag_dsnull) return null;
			else return ds_Data;
		
		}

		public DataSet QuyetToanKP_(AccessData a, string s_IDlk,string s_IDChuong, string s_IDHoatdong, string s_IDNguongoc,string s_tuthang,string s_denthang,string s_yy,string s_idnhom)
		{
			#region lay cac field va noidungmuc
			sql = "SELECT id,loai,khoan,loaikhoan,tenloaikhoan,t1.muc,tm,noidungtm,noidungmuc,manguon,nhom,stk,sotien,thang,nsnn,lephidelai, ";
			sql += " vientro,nguonkhac,group1,num_group1,group2, num_group2,lk_nsnn,  lk_lephidelai,  lk_vientro, lk_nguonkhac";
			sql += " FROM";
			sql += " (SELECT DISTINCT ch.id as id,substr(trim(lk.lk),0,3) as loai,substr(trim(lk.lk),5,3) as khoan,";
			sql+=" lk.lk as loaikhoan,lk.tlk as tenloaikhoan,substr(trim(ch.mtm),0,4) ";
			sql += " as muc,substr(trim(ch.mtm),6,4) as tm, substr(trim(ng.mang),0,2) as manguon,";
//			sql+=" case when (substr())";
			sql+=" muc.nhom as nhom,tk.stk as stk,ch.ttk as noidungtm,ctct.stien ";
			sql += " as sotien,ct.thanggs as thang, 0 as nsnn,0 as lephidelai, 0 as vientro,0 as nguonkhac,'' as group1,'' as num_group1,'' as group2,'' as ";
			sql += " num_group2 ,0 as lk_nsnn, 0 as lk_lephidelai, 0 as lk_vientro, 0 as lk_nguonkhac ";			
			sql += " FROM a_ctct" + s_yy + " ctct INNER JOIN a_dmtk tk ON tk.id=ctct.tkcoa OR tk.id=ctct.tknoa INNER JOIN a_dmch ch ON (ctct.mtmno = ch.id OR ctct.mtmco = ch.id) ";
			sql += " INNER JOIN a_dmng ng ON (substr(trim(tk.stk),7,length(ng.mang))=ng.mang) OR";
			sql += " (substr(trim(tk.stk),6,length(ng.mang))=ng.mang) LEFT JOIN a_dmlk lk ON lk.id = ctct.lk INNER JOIN a_ct" + s_yy + " ct ON ct.id = ctct.idct  LEFT JOIN";
			sql += " a_dmnhom muc ON ch.nhmuc = muc.id  LEFT JOIN a_dmchuong chuong ON chuong.id=ct.chuong  INNER JOIN a_dmnhombc bc ON bc.id = ct.idbc ";
			if (s_tuthang !="" || s_denthang!="")
				sql += " WHERE ct.thanggs BETWEEN "+ s_tuthang + " AND " + s_denthang;
			if (s_IDChuong!="") 
				sql += " AND ct.chuong=" + s_IDChuong;
			if (s_IDHoatdong!="") 
				sql += " AND ct.hoatdong=" + s_IDHoatdong;
			if (s_IDNguongoc!="") 
				sql += " AND ng.id=" + s_IDNguongoc;			
			if (s_IDlk!="") 
				sql += " AND ctct.lk=" + s_IDlk;
			if (s_idnhom!="") 
				sql += " AND ct.idbc=" + s_idnhom;
			sql += " AND (substr(trim(tk.stk),0,5)) like '66121%'" ;
			sql += " OR (substr(trim(tk.stk),0,5)) like '66122%' ";
			sql += " OR (substr(trim(tk.stk),0,4)) like '6621%'";
			sql += " OR (substr(trim(tk.stk),0,4)) like '6622%'";			
			sql += " ORDER BY tk.stk ) t1";
			sql += " INNER JOIN ";
			sql += " (SELECT ch.mtm as muc, ch.ttk as noidungmuc FROM a_dmch ch where ch.cd=3 ORDER BY ch.mtm) t2 ON t1.muc=t2.muc";
			try
			{
				ds_Data = a.get_data(sql).Copy();
				if(ds_Data.Tables[0].Rows.Count<=0)
					flag_dsnull=true;
			}
			catch
			{
				flag_dsnull = true;
			}  
			#endregion			

			#region them cot nsnn,lephidelai,vientro, nguonkhac vao dataset
			if (flag_dsnull != true)
			{				
				int countRow=ds_Data.Tables[0].Rows.Count;				
				for(int j=0;j<countRow;j++)
				{		
					try
					{
						decimal sotien = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["sotien"].ToString());
						decimal nsnn = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["nsnn"].ToString());
						decimal lephidelai = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["lephidelai"].ToString());
						decimal vientro = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["vientro"].ToString());
						decimal nguonkhac = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["nguonkhac"].ToString());
						string manguon = (ds_Data.Tables[0].Rows[j]["manguon"].ToString());

						if (manguon=="01" || manguon=="02")
						{
							nsnn += sotien;
							vientro=0;
							lephidelai=0;
							nguonkhac=0;
						}
						else if (manguon=="04")
						{	
							lephidelai +=sotien;
							vientro=0;
							nsnn=0;
							nguonkhac=0;
						}
						else if (manguon=="03")
						{
							lephidelai =0;
							vientro += sotien;
							nsnn=0;
							nguonkhac=0;
						}
						else
						{
							lephidelai =0;
							vientro = 0;
							nsnn=0;
							nguonkhac+=sotien;
						}
				
						ds_Data.Tables[0].Rows[j]["nsnn"] = nsnn;	
						ds_Data.Tables[0].Rows[j]["lephidelai"] = lephidelai;	
						ds_Data.Tables[0].Rows[j]["vientro"] = vientro;	
						ds_Data.Tables[0].Rows[j]["nguonkhac"] = nguonkhac;						
					}
					catch (Exception Ex)
					{
						MessageBox.Show("Error : " + Ex ,"Thông báo !");
					}		
				}
			}
			ds_Data.AcceptChanges();
			#endregion												
			
			#region tao cac cot de group theo loai khoan 			
			if (flag_dsnull != true)
			{				
				int countRow1=ds_Data.Tables[0].Rows.Count;
				for(int j=0;j<countRow1;j++)
				{
					try
					{
						string group1 = (ds_Data.Tables[0].Rows[j]["group1"].ToString());
						string num_group1 = (ds_Data.Tables[0].Rows[j]["num_group1"].ToString());
						string group2 = (ds_Data.Tables[0].Rows[j]["group2"].ToString());
						string num_group2 = (ds_Data.Tables[0].Rows[j]["num_group2"].ToString());
						string stk = ((ds_Data.Tables[0].Rows[j]["stk"].ToString())).Trim().Split('.')[0].ToString();
						if (stk.StartsWith("661"))
						{
							group1="I - CHI HOẠT ĐỘNG";
							num_group1="1";
							if (stk.StartsWith("66121"))
							{
								group2="1. CHI THƯỜNG XUYÊN";
								num_group2="1.1";
							}
							if (stk.StartsWith("66122"))
							{
								group2="2. CHI KHÔNG THƯỜNG XUYÊN";
								num_group2="1.1";
							}
						}
						if (stk.StartsWith("662"))
						{
							group1="II - CHI DỰ ÁN";
							num_group1="2";
							if (stk.StartsWith("6621"))
							{
								group2="1. CHI QUẢN LÝ DỰ ÁN";
								num_group2="2.1";
							}
							if (stk.StartsWith("6622"))
							{
								group2="2. CHI THỰC HIỆN DỰ ÁN";
								num_group2="2.2";
							}
						}
						ds_Data.Tables[0].Rows[j]["group1"] = group1;
						ds_Data.Tables[0].Rows[j]["num_group1"] = num_group1;
						ds_Data.Tables[0].Rows[j]["group2"] = group2;
						ds_Data.Tables[0].Rows[j]["num_group2"] = num_group2;
						
					}
					catch (Exception Ex)
					{
						MessageBox.Show("Error : " + Ex ,"Thông báo !");
					}				
				}
			}
			ds_Data.AcceptChanges();
			#endregion
					
			if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
			ds_Data.WriteXml("..\\xml\\KT_TongHopTinhHinhKP_QuyetToanKP2_.xml",XmlWriteMode.WriteSchema);
			if (flag_dsnull) return null;
			else return ds_Data;
		
		}


		/// <summary>
		/// Tao file xml "KT_TongHopTinhHinhKP_QuyetToanKP2.xml" cho report KT_TongHopTinhHinhKP_QuyetToanKP2.rpt
		/// </summary>		
		public DataSet QuyetToanKP(AccessData a, string s_IDlk,string s_IDChuong, string s_IDHoatdong, string s_IDNguongoc,string s_tuthang,string s_denthang,string s_yy,string s_idnhom)
		{
			#region  DATASET1 ( tuthang - denthang)
			#region lay cac field bang cau query
			sql = " SELECT T1.*,T2.noidungmuc" ;
			sql += " FROM (";
			sql += " SELECT DISTINCT ch.id as id,substr(trim(lk.lk),0,3) as loai,substr(trim(lk.lk),5,3) as khoan,lk.lk as loaikhoan,lk.tlk as tenloaikhoan,substr(trim(ch.mtm),0,4) ";
			sql += " as muc,substr(trim(ch.mtm),6,4) as tm, substr(trim(ng.mang),0,2) as manguon,muc.nhom as nhom,tk.stk as stk,ch.ttk as noidungtm,ctct.stien ";
			sql += " as sotien,ct.thanggs as thang, 0 as nsnn,0 as lephidelai, 0 as vientro,0 as nguonkhac,'' as group1,'' as num_group1,'' as group2,'' as ";
			sql += " num_group2 ,0 as lk_nsnn, 0 as lk_lephidelai, 0 as lk_vientro, 0 as lk_nguonkhac, 0 as sapxep ";			
			sql += " FROM a_ctct" + s_yy + " ctct INNER JOIN a_dmtk tk ON tk.id=ctct.tkcoa OR tk.id=ctct.tknoa INNER JOIN a_dmch ch ON (ctct.mtmno = ch.id OR ctct.mtmco = ch.id) ";
			sql += " INNER JOIN a_dmng ng ON (substr(trim(tk.stk),7,length(ng.mang))=ng.mang) OR";
			sql += " (substr(trim(tk.stk),6,length(ng.mang))=ng.mang) LEFT JOIN a_dmlk lk ON lk.id = ctct.lk INNER JOIN a_ct" + s_yy + "  ct ON ct.id = ctct.idct  LEFT JOIN";
			sql += " a_dmnhom muc ON ch.nhmuc = muc.id  LEFT JOIN a_dmchuong chuong ON chuong.id=ct.chuong  INNER JOIN a_dmnhombc bc ON bc.id = ct.idbc ";
			if (s_tuthang !="" || s_denthang!="")
				sql += " WHERE ct.thanggs BETWEEN "+ s_tuthang + " AND " + s_denthang;
			if (s_IDChuong!="") 
				sql += " AND ct.chuong=" + s_IDChuong;
			if (s_IDHoatdong!="") 
				sql += " AND ct.hoatdong=" + s_IDHoatdong;
			if (s_IDNguongoc!="") 
				sql += " AND ng.id=" + s_IDNguongoc;			
			if (s_IDlk!="") 
				sql += " AND ctct.lk=" + s_IDlk;
			if (s_idnhom!="") 
				sql += " AND ct.idbc=" + s_idnhom;
			sql += " AND (substr(trim(tk.stk),0,5)) like '66121%'" ;
			sql += " OR (substr(trim(tk.stk),0,5)) like '66122%' ";
			sql += " OR (substr(trim(tk.stk),0,4)) like '6621%'";
			sql += " OR (substr(trim(tk.stk),0,4)) like '6622%'";			
			sql += " ORDER BY tk.stk ";
			sql += " ) t1 INNER JOIN ";
			sql += " (SELECT ch.mtm as muc, ch.ttk as noidungmuc FROM a_dmch ch where ch.cd=3 ORDER BY ch.mtm) t2 ON t1.muc=t2.muc";

			try
			{
				ds_Data = a.get_data(sql).Copy();
				if(ds_Data.Tables[0].Rows.Count<=0)
					flag_dsnull=true;
			}
			catch
			{
				flag_dsnull = true;
			}  
			#endregion
			
			#region them cot nsnn,lephidelai,vientro, nguonkhac vao dataset
			if (flag_dsnull != true)
			{				
				int countRow=ds_Data.Tables[0].Rows.Count;				
				for(int j=0;j<countRow;j++)
				{		
					try
					{
						decimal sotien = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["sotien"].ToString());
						decimal nsnn = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["nsnn"].ToString());
						decimal lephidelai = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["lephidelai"].ToString());
						decimal vientro = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["vientro"].ToString());
						decimal nguonkhac = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["nguonkhac"].ToString());
						string manguon = (ds_Data.Tables[0].Rows[j]["manguon"].ToString());

						if (manguon=="01" || manguon=="02")
						{
							nsnn += sotien;
							vientro=0;
							lephidelai=0;
							nguonkhac=0;
						}
						else if (manguon=="04")
						{	
							lephidelai +=sotien;
							vientro=0;
							nsnn=0;
							nguonkhac=0;
						}
						else if (manguon=="03")
						{
							lephidelai =0;
							vientro += sotien;
							nsnn=0;
							nguonkhac=0;
						}
						else
						{
							lephidelai =0;
							vientro = 0;
							nsnn=0;
							nguonkhac+=sotien;
						}
				
						ds_Data.Tables[0].Rows[j]["nsnn"] = nsnn;	
						ds_Data.Tables[0].Rows[j]["lephidelai"] = lephidelai;	
						ds_Data.Tables[0].Rows[j]["vientro"] = vientro;	
						ds_Data.Tables[0].Rows[j]["nguonkhac"] = nguonkhac;						
					}
					catch (Exception Ex)
					{
						MessageBox.Show("Error : " + Ex ,"Thông báo !");
					}		
				}
			}
			ds_Data.AcceptChanges();
			#endregion												
			
			#region tao cac cot de group theo loai khoan 			
			if (flag_dsnull != true)
			{				
				int countRow1=ds_Data.Tables[0].Rows.Count;
				for(int j=0;j<countRow1;j++)
				{
					try
					{
						string group1 = (ds_Data.Tables[0].Rows[j]["group1"].ToString());
						string num_group1 = (ds_Data.Tables[0].Rows[j]["num_group1"].ToString());
						string group2 = (ds_Data.Tables[0].Rows[j]["group2"].ToString());
						string num_group2 = (ds_Data.Tables[0].Rows[j]["num_group2"].ToString());
						string stk = ((ds_Data.Tables[0].Rows[j]["stk"].ToString())).Trim().Split('.')[0].ToString();
						if (stk.StartsWith("661"))
						{
							group1="I - CHI HOẠT ĐỘNG";
							num_group1="1";
							if (stk.StartsWith("66121"))
							{
								group2="1. CHI THƯỜNG XUYÊN";
								num_group2="1.1";
							}
							if (stk.StartsWith("66122"))
							{
								group2="2. CHI KHÔNG THƯỜNG XUYÊN";
								num_group2="1.1";
							}
						}
						if (stk.StartsWith("662"))
						{
							group1="II - CHI DỰ ÁN";
							num_group1="2";
							if (stk.StartsWith("6621"))
							{
								group2="1. CHI QUẢN LÝ DỰ ÁN";
								num_group2="2.1";
							}
							if (stk.StartsWith("6622"))
							{
								group2="2. CHI THỰC HIỆN DỰ ÁN";
								num_group2="2.2";
							}
						}
						ds_Data.Tables[0].Rows[j]["group1"] = group1;
						ds_Data.Tables[0].Rows[j]["num_group1"] = num_group1;
						ds_Data.Tables[0].Rows[j]["group2"] = group2;
						ds_Data.Tables[0].Rows[j]["num_group2"] = num_group2;
						
					}
					catch (Exception Ex)
					{
						MessageBox.Show("Error : " + Ex ,"Thông báo !");
					}				
				}
			}
			ds_Data.AcceptChanges();
//			ds_Data.WriteXml("..\\xml\\KT_t4.xml",XmlWriteMode.WriteSchema);
			#endregion

			#endregion
			
			#region DATASET2 ( 1 - denthang)			

			#region lay cac field bang cau query
			sql1 = " SELECT T1.*,T2.noidungmuc" ;
			sql1 += " FROM (";
			sql1 += " SELECT  DISTINCT ch.id as id,substr(trim(lk.lk),0,3) as loai,substr(trim(lk.lk),5,3) as khoan,lk.lk as loaikhoan,lk.tlk as tenloaikhoan,substr(trim(ch.mtm),0,4) ";
			sql1 += " as muc,substr(trim(ch.mtm),6,4) as tm, substr(trim(ng.mang),0,2) as manguon,muc.nhom as nhom,tk.stk as stk,ch.ttk as noidungtm,ctct.stien ";
			sql1 += " as sotien,ct.thanggs as thang, 0 as nsnn,0 as lephidelai, 0 as vientro,0 as nguonkhac,'' as group1,'' as num_group1,'' as group2,'' as ";
			sql1 += " num_group2 ,0 as lk_nsnn, 0 as lk_lephidelai, 0 as lk_vientro, 0 as lk_nguonkhac, 1 as sapxep ";			
			sql1 += " FROM a_ctct" + s_yy + " ctct INNER JOIN a_dmtk tk ON tk.id=ctct.tkcoa OR tk.id=ctct.tknoa INNER JOIN a_dmch ch ON (ctct.mtmno = ch.id OR ctct.mtmco = ch.id) ";
			sql1 += " INNER JOIN a_dmng ng ON (substr(trim(tk.stk),7,length(ng.mang))=ng.mang) OR";
			sql1 += " (substr(trim(tk.stk),6,length(ng.mang))=ng.mang) LEFT JOIN a_dmlk lk ON lk.id = ctct.lk INNER JOIN a_ct" + s_yy + " ct ON ct.id = ctct.idct  LEFT JOIN";
			sql1 += " a_dmnhom muc ON ch.nhmuc = muc.id  LEFT JOIN a_dmchuong chuong ON chuong.id=ct.chuong  INNER JOIN a_dmnhombc bc ON bc.id = ct.idbc ";
//				if (s_tuthang !="" || s_denthang!="")
//					if (Convert.ToInt16(s_tuthang)==1)
//					{
						sql1 += " WHERE ct.thanggs BETWEEN 1 AND " + s_denthang;				
//					}
//					else
//					{
//						sql1 += " WHERE ct.thanggs BETWEEN 1 AND " + (Convert.ToInt16(s_tuthang)-1);
//					}
			if (s_IDChuong!="") 
				sql1 += " AND ct.chuong=" + s_IDChuong;
			if (s_IDHoatdong!="") 
				sql1 += " AND ct.hoatdong=" + s_IDHoatdong;
			if (s_IDNguongoc!="") 
				sql1 += " AND ng.id=" + s_IDNguongoc;			
			if (s_IDlk!="") 
				sql1 += " AND ctct.lk=" + s_IDlk;
			if (s_idnhom!="") 
				sql1 += " AND ct.idbc=" + s_idnhom;
			sql1 += " AND (substr(trim(tk.stk),0,5)) like '66121%'" ;
			sql1 += " OR (substr(trim(tk.stk),0,5)) like '66122%' ";
			sql1 += " OR (substr(trim(tk.stk),0,4)) like '6621%'";
			sql1 += " OR (substr(trim(tk.stk),0,4)) like '6622%'";			
			sql1 += " ORDER BY tk.stk ";
			sql1 += " ) t1 INNER JOIN ";
			sql1 += " (SELECT ch.mtm as muc, ch.ttk as noidungmuc FROM a_dmch ch where ch.cd=3 ORDER BY ch.mtm) t2 ON t1.muc=t2.muc";

			try
			{
				ds_Data_ = a.get_data(sql1).Copy();
				if(ds_Data_.Tables[0].Rows.Count<=0)
					flag_dsnull=true;
			}
			catch
			{
				flag_dsnull = true;
			}  
		#endregion		

			#region them cot nsnn,lephidelai,vientro, nguonkhac vao dataset
				if (flag_dsnull != true)
				{			
					decimal sotien=0,nsnn_=0,lephidelai_=0,vientro_=0,nguonkhac_=0,nsnn1=0,lephidelai1=0,vientro1=0,nguonkhac1=0;
					string manguon="";
					int countRow=ds_Data_.Tables[0].Rows.Count;				
//						int countRow1=ds_Data.Tables[0].Rows.Count;				
					for(int j=0;j<countRow;j++)
					{		
						try
						{
							sotien = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["sotien"].ToString());
							nsnn_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_nsnn"].ToString());
							lephidelai_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_lephidelai"].ToString());
							vientro_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_vientro"].ToString());
							nguonkhac_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_nguonkhac"].ToString());
							manguon = (ds_Data_.Tables[0].Rows[j]["manguon"].ToString());
							if (manguon=="01" || manguon=="02")
							{
								nsnn_ += sotien;
								vientro_=0;
								lephidelai_=0;
								nguonkhac_=0;
							}
							else if (manguon=="04")
							{	
								lephidelai_ +=sotien;
								vientro_=0;
								nsnn_=0;
								nguonkhac_=0;
							}
							else if (manguon=="03")
							{
								lephidelai_ =0;
								vientro_ += sotien;
								nsnn_=0;
								nguonkhac_=0;
							}
							else
							{
								lephidelai_ =0;
								vientro_ = 0;
								nsnn_=0;
								nguonkhac_+=sotien;
							}

							ds_Data_.Tables[0].Rows[j]["lk_nsnn"] = nsnn_;	
							ds_Data_.Tables[0].Rows[j]["lk_lephidelai"] = lephidelai_;	
							ds_Data_.Tables[0].Rows[j]["lk_vientro"] = vientro_;	
							ds_Data_.Tables[0].Rows[j]["lk_nguonkhac"] = nguonkhac_;
//								ds_Data.Tables[0].Rows[j]["lk_nsnn"] = nsnn_;	
//								ds_Data.Tables[0].Rows[j]["lk_lephidelai"] = lephidelai_;	
//								ds_Data.Tables[0].Rows[j]["lk_vientro"] = vientro_;	
//								ds_Data.Tables[0].Rows[j]["lk_nguonkhac"] = nguonkhac_;	
						}
						catch (Exception Ex)
						{
							MessageBox.Show("Error : " + Ex ,"Thông báo !");
						}		
					}

				}

				ds_Data_.AcceptChanges();

//			for(int j=0;j<countRow;j++)
//			{
//				nsnn_ = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["lk_nsnn"].ToString());
//				lephidelai_ = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["lk_lephidelai"].ToString());
//				vientro_ = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["lk_vientro"].ToString());
//				nguonkhac_ = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["lk_nguonkhac"].ToString());
//				nsnn1 +=nsnn_;
//				lephidelai1 +=lephidelai_;
//				vientro1 +=vientro_;
//				nguonkhac1 +=nguonkhac_;
//				ds_Data.Tables[0].Rows[j]["lk_nsnn"] = nsnn1;	
//				ds_Data.Tables[0].Rows[j]["lk_lephidelai"] = lephidelai1;	
//				ds_Data.Tables[0].Rows[j]["lk_vientro"] = vientro1;	
//				ds_Data.Tables[0].Rows[j]["lk_nguonkhac"] = nguonkhac1;	
//								
//
//			}
//			ds_Data_.AcceptChanges();	
//			ds_Data_.WriteXml("..\\xml\\KT_DS.xml",XmlWriteMode.WriteSchema);
			#endregion												

			#region tao cac cot de group theo loai khoan 			
			if (flag_dsnull != true)
			{				
				int countRow1=ds_Data_.Tables[0].Rows.Count;
				for(int j=0;j<countRow1;j++)
				{
					try
					{
						string group1 = (ds_Data_.Tables[0].Rows[j]["group1"].ToString());
						string num_group1 = (ds_Data_.Tables[0].Rows[j]["num_group1"].ToString());
						string group2 = (ds_Data_.Tables[0].Rows[j]["group2"].ToString());
						string num_group2 = (ds_Data_.Tables[0].Rows[j]["num_group2"].ToString());
						string stk = ((ds_Data_.Tables[0].Rows[j]["stk"].ToString())).Trim().Split('.')[0].ToString();
						if (stk.StartsWith("661"))
						{
							group1="I - CHI HOẠT ĐỘNG";
							num_group1="1";
							if (stk.StartsWith("66121"))
							{
								group2="1. CHI THƯỜNG XUYÊN";
								num_group2="1.1";
							}
							if (stk.StartsWith("66122"))
							{
								group2="2. CHI KHÔNG THƯỜNG XUYÊN";
								num_group2="1.1";
							}
						}
						if (stk.StartsWith("662"))
						{
							group1="II - CHI DỰ ÁN";
							num_group1="2";
							if (stk.StartsWith("6621"))
							{
								group2="1. CHI QUẢN LÝ DỰ ÁN";
								num_group2="2.1";
							}
							if (stk.StartsWith("6622"))
							{
								group2="2. CHI THỰC HIỆN DỰ ÁN";
								num_group2="2.2";
							}
						}
						ds_Data_.Tables[0].Rows[j]["group1"] = group1;
						ds_Data_.Tables[0].Rows[j]["num_group1"] = num_group1;
						ds_Data_.Tables[0].Rows[j]["group2"] = group2;
						ds_Data_.Tables[0].Rows[j]["num_group2"] = num_group2;
					
					}
					catch {}		
				}
			}
			ds_Data_.AcceptChanges();

			
		#endregion

				try
				{
								
					if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
					else
					{							
						ds_Data.Merge(ds_Data_);
						
					}				
				
				}
				catch {}
			#endregion				

			if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
			ds_Data.WriteXml("..\\xml\\KT_TongHopTinhHinhKP_QuyetToanKP2.xml",XmlWriteMode.WriteSchema);
			if (flag_dsnull) return null;
			else return ds_Data;		
		}
		public DataSet QuyetToanKP_La_(AccessData a, string s_IDlk,string s_IDChuong, string s_IDHoatdong, string s_IDNguongoc,string s_tuthang,string s_denthang,string s_yy,string s_idnhom)
		{
			#region lay cac field va noidungmuc
			sql = "SELECT id,loai,khoan,loaikhoan,tenloaikhoan,t1.muc,tm,noidungtm,noidungmuc,manguon,nhom,stk,sotien,thang,nsnn,cbnh,kpdh,kpca,mtqg,kp_treem, vienphi, dichvu,thukhac, thangmay ";
			sql += " ,group1,num_group1,group2, num_group2,lk_nsnn,  lk_cbnh, lk_kpdh,lk_kpca ,lk_mtqg, lk_treem ,lk_vienphi, lk_dichvu,lk_thukhac, lk_thangmay ";
			sql += " FROM";
			sql += " (SELECT ch.id as id,substr(trim(lk.lk),0,3) as loai,substr(trim(lk.lk),5,3) as khoan,lk.lk as loaikhoan,lk.tlk as tenloaikhoan,substr(trim(ch.mtm),0,4) ";
			sql += " as muc,substr(trim(ch.mtm),6,4) as tm, ng.mang as manguon,muc.nhom as nhom,tk.stk as stk,ch.ttk as noidungtm,ctct.stien ";
			sql += " as sotien,ct.thanggs as thang, 0 as nsnn,0 as cbnh, 0 as kpdh, 0 as kpca, 0 as mtqg,0 as kp_treem,0 as vienphi,0 as dichvu, 0 as thukhac, 0 as thangmay ,'' as group1,'' as num_group1,'' as group2,'' as ";
			sql += " num_group2 ,0 as lk_nsnn, 0 as lk_cbnh, 0 as lk_kpdh, 0 as lk_kpca,0 as lk_mtqg, 0 as lk_treem, 0 as lk_vienphi, 0 as lk_dichvu,0 as lk_thukhac, 0 as lk_thangmay ";			
			sql += " FROM a_ctct" + s_yy + " ctct INNER JOIN a_dmtk tk ON tk.id=ctct.tkcoa OR tk.id=ctct.tknoa INNER JOIN a_dmch ch ON (ctct.mtmno = ch.id OR ctct.mtmco = ch.id) ";
			sql += " INNER JOIN a_dmng ng ON (substr(trim(tk.stk),7,length(ng.mang))=ng.mang) OR";
			sql += " (substr(trim(tk.stk),6,length(ng.mang))=ng.mang) LEFT JOIN a_dmlk lk ON lk.id = ctct.lk INNER JOIN a_ct" + s_yy + " ct ON ct.id = ctct.idct  LEFT JOIN";
			sql += " a_dmnhom muc ON ch.nhmuc = muc.id  LEFT JOIN a_dmchuong chuong ON chuong.id=ct.chuong  INNER JOIN a_dmnhombc bc ON bc.id = ct.idbc ";
			if (s_tuthang !="" || s_denthang!="")
				sql += " WHERE ct.thanggs BETWEEN "+ s_tuthang + " AND " + s_denthang;
			if (s_IDChuong!="") 
				sql += " AND ct.chuong=" + s_IDChuong;
			if (s_IDHoatdong!="") 
				sql += " AND ct.hoatdong=" + s_IDHoatdong;
			if (s_IDNguongoc!="") 
				sql += " AND ng.id=" + s_IDNguongoc;			
			if (s_IDlk!="") 
				sql += " AND ctct.lk=" + s_IDlk;
			if (s_idnhom!="") 
				sql += " AND ct.idbc=" + s_idnhom;
			sql += " AND (substr(trim(tk.stk),0,5)) like '66121%'" ;
			sql += " OR (substr(trim(tk.stk),0,5)) like '66122%' ";
			sql += " OR (substr(trim(tk.stk),0,5)) like '46121%'";
			//sql += " OR (substr(trim(tk.stk),0,5)) like '46122%'";			
			sql += " ORDER BY tk.stk ) t1";
			sql += " INNER JOIN ";
			sql += " (SELECT ch.mtm as muc, ch.ttk as noidungmuc FROM a_dmch ch where ch.cd=3 ORDER BY ch.mtm) t2 ON t1.muc=t2.muc";
			try
			{
				ds_Data = a.get_data(sql).Copy();
				if(ds_Data.Tables[0].Rows.Count<=0)
					flag_dsnull=true;
			}
			catch
			{
				flag_dsnull = true;
			}  
			#endregion			

			#region them cot nsnn,cbnh,mtqg,kpdh,kpca, kp_treem, vienphi, dichvu ,thukhac, thangmay vao dataset
			if (flag_dsnull != true)
			{				
				int countRow=ds_Data.Tables[0].Rows.Count;				
				for(int j=0;j<countRow;j++)
										  {		
											  try
											  {
												  decimal sotien = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["sotien"].ToString());
												  decimal nsnn = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["nsnn"].ToString());
												  decimal cbnh = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["cbnh"].ToString());
												  decimal kpdh = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["kpdh"].ToString());
												  decimal kpca = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["kpca"].ToString());
												  decimal mtqg = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["mtqg"].ToString());
												  decimal kp_treem = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["kp_treem"].ToString());
												  decimal vienphi = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["vienphi"].ToString());
												  decimal dichvu = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["dichvu"].ToString());
												  decimal thukhac = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["thukhac"].ToString());
												  decimal thangmay = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["thangmay"].ToString());
												  string manguon = (ds_Data.Tables[0].Rows[j]["manguon"].ToString());

												  if (manguon=="0113")
												  {
													  nsnn += sotien;
													  cbnh=0;
													  kpdh = 0;
													  kpca= 0;
													  mtqg=0;
													  kp_treem=0;
													  vienphi = 0;
													  dichvu = 0;
													  thukhac = 0;
													  thangmay = 0;
												  }
												  else if (manguon=="02121")
												  {	
													  cbnh += sotien;
													  nsnn = 0 ;
													  kpdh = 0;
													  kpca =0;
													  mtqg=0;
													  kp_treem=0;
													  vienphi=0;
													  dichvu =0;
													  thukhac =0 ;
													  thangmay = 0;
												  }
												  else if (manguon=="02122")
												  {	
													  kpdh += sotien;
													  nsnn = 0 ;
													  cbnh = 0;
													  kpca =0;
													  mtqg=0;
													  kp_treem=0;
													  vienphi=0;
													  dichvu =0;
													  thukhac =0 ;
													  thangmay = 0;
												  }
												  else if (manguon=="02123")
												  {	
													  kpca += sotien;
													  nsnn = 0 ;
													  cbnh = 0;
													  kpdh =0;
													  mtqg=0;
													  kp_treem=0;
													  vienphi=0;
													  dichvu =0;
													  thukhac =0 ;
													  thangmay = 0;
												  }
												  else if (manguon=="0214")
												  {
													  nsnn =0;
													  cbnh = 0;
													  kpdh = 0;
													  kpca = 0;
													  mtqg += sotien;
													  kp_treem=0;
													  vienphi =0;
													  dichvu = 0;
													  thukhac = 0;
													  thangmay= 0;
												  }
												  else if (manguon=="0218")
												  {
													  nsnn =0;
													  cbnh = 0;
													  kpdh = 0;
													  kpca =0;
													  mtqg = 0 ;
													  kp_treem += sotien;
													  vienphi =0;
													  dichvu =0;
													  thukhac = 0;
													  thangmay= 0;
												  }
												  else if (manguon=="0401" )
												  {
													  nsnn =0;
													  cbnh = 0;
													  kpdh=0;
													  kpca = 0;
													  mtqg = 0 ;
													  kp_treem =0;
													  vienphi += sotien;
													  dichvu = 0;
													  thukhac = 0;
													  thangmay= 0;
												  }
												  else if ( manguon == "0501" )
												  {
													  nsnn =0;
													  cbnh = 0;
													  kpdh=0;
													  kpca = 0;
													  mtqg = 0 ;
													  kp_treem =0;
													  dichvu += sotien;
													  vienphi = 0;
													  thukhac = 0;
													  thangmay= 0;
												  }
												  else if (manguon=="0402")
												  {
													  nsnn =0;
													  cbnh = 0;
													  kpdh= 0;
													  kpca = 0;
													  mtqg = 0 ;
													  kp_treem = 0;
													  vienphi =0;
													  dichvu = 0;
													  thukhac += sotien;
													  thangmay= 0;
												  }
	
												  else if (manguon=="0502")
												  {
													  nsnn =0;
													  cbnh = 0;
													  kpdh = 0;
													  kpca = 0;
													  mtqg = 0 ;
													  kp_treem = 0;
													  vienphi =0;
													  dichvu =0;
													  thukhac = 0;
													  thangmay+= sotien;
												  }
				
												  ds_Data.Tables[0].Rows[j]["nsnn"] = nsnn;	
												  ds_Data.Tables[0].Rows[j]["cbnh"] = cbnh;
												  ds_Data.Tables[0].Rows[j]["kpdh"] = kpdh;
												  ds_Data.Tables[0].Rows[j]["kpca"] = kpca;
												  ds_Data.Tables[0].Rows[j]["mtqg"] = mtqg;	
												  ds_Data.Tables[0].Rows[j]["kp_treem"] = kp_treem;
												  ds_Data.Tables[0].Rows[j]["vienphi"] = vienphi;
												  ds_Data.Tables[0].Rows[j]["dichvu"] = dichvu;
												  ds_Data.Tables[0].Rows[j]["thukhac"] = thukhac;
												  ds_Data.Tables[0].Rows[j]["thangmay"] = thangmay;
					
											  }
											  catch (Exception Ex)
											  {
												  MessageBox.Show("Error : " + Ex ,"Thông báo !");
											  }		
										  }
			}
			
			ds_Data.AcceptChanges();
			
			#endregion												
			
			#region tao cac cot de group theo loai khoan 			
			if (flag_dsnull != true)
			{				
				int countRow1=ds_Data.Tables[0].Rows.Count;
				for(int j=0;j<countRow1;j++)
				{
					try
					{
						string group1 = (ds_Data.Tables[0].Rows[j]["group1"].ToString());
						string num_group1 = (ds_Data.Tables[0].Rows[j]["num_group1"].ToString());
						string group2 = (ds_Data.Tables[0].Rows[j]["group2"].ToString());
						string num_group2 = (ds_Data.Tables[0].Rows[j]["num_group2"].ToString());
						string stk = ((ds_Data.Tables[0].Rows[j]["stk"].ToString())).Trim().Split('.')[0].ToString();
						if (stk.StartsWith("661"))
						{
							group1="I - CHI HOẠT ĐỘNG";
							num_group1="1";
							if (stk.StartsWith("66121"))
							{
								group2="1. CHI THƯỜNG XUYÊN";
								num_group2="1.1";
							}
							if (stk.StartsWith("66122"))
							{
								group2="2. CHI KHÔNG THƯỜNG XUYÊN";
								num_group2="1.1";
							}
						}
						if (stk.StartsWith("662"))
						{
							group1="II - CHI DỰ ÁN";
							num_group1="2";
							if (stk.StartsWith("6621"))
							{
								group2="1. CHI QUẢN LÝ DỰ ÁN";
								num_group2="2.1";
							}
							if (stk.StartsWith("6622"))
							{
								group2="2. CHI THỰC HIỆN DỰ ÁN";
								num_group2="2.2";
							}
						}
						ds_Data.Tables[0].Rows[j]["group1"] = group1;
						ds_Data.Tables[0].Rows[j]["num_group1"] = num_group1;
						ds_Data.Tables[0].Rows[j]["group2"] = group2;
						ds_Data.Tables[0].Rows[j]["num_group2"] = num_group2;
						
					}
					catch (Exception Ex)
					{
						MessageBox.Show("Error : " + Ex ,"Thông báo !");
					}				
				}
			}
			ds_Data.AcceptChanges();
			#endregion
					
			if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
			ds_Data.WriteXml("..\\xml\\KT_linh.xml", XmlWriteMode.WriteSchema);
			if (flag_dsnull) return null;
			else return ds_Data;
		
		}
		//thêm dataset này để tính lũy kế 
		public DataSet QuyetToanKP_la(AccessData a, string s_IDlk,string s_IDChuong, string s_IDHoatdong, string s_IDNguongoc,string s_tuthang,string s_denthang,string s_yy,string s_idnhom)
		{
			#region  DATASET1 ( tuthang - denthang)
			#region lay cac field bang cau query
			sql = " SELECT T1.*,T2.noidungmuc" ;
			sql += " FROM (";
			sql += " SELECT DISTINCT ch.id as id,substr(trim(lk.lk),0,3) as loai,substr(trim(lk.lk),5,3) as khoan,lk.lk as loaikhoan,lk.tlk as tenloaikhoan,substr(trim(ch.mtm),0,4) ";
			sql += " as muc,substr(trim(ch.mtm),6,4) as tm, ng.mang as manguon,muc.nhom as nhom,tk.stk as stk,ch.ttk as noidungtm,ctct.stien ";
			sql += " as sotien,ct.thanggs as thang, 0 as nsnn,0 as cbnh, 0 as kpdh, 0 as kpca ,0 as mtqg,0 as kp_treem,0 as vienphi, 0 as dichvu,0 as thukhac, 0 as thangmay,'' as group1,'' as num_group1,'' as group2,'' as ";
			sql += " num_group2 ,0 as lk_nsnn, 0 as lk_cbnh, 0 as  lk_kpdh, 0 as lk_kpca, 0 as lk_mtqg, 0 as lk_treem,0 as lk_vienphi,0 as lk_dichvu,0 as lk_thukhac,0 as lk_thangmay, 0 as sapxep ";			
			sql += " FROM a_ctct" + s_yy + " ctct INNER JOIN a_dmtk tk ON tk.id=ctct.tkcoa OR tk.id=ctct.tknoa INNER JOIN a_dmch ch ON (ctct.mtmno = ch.id OR ctct.mtmco = ch.id) ";
			sql += " INNER JOIN a_dmng ng ON (substr(trim(tk.stk),7,length(ng.mang))=ng.mang) OR";
			sql += " (substr(trim(tk.stk),6,length(ng.mang))=ng.mang) LEFT JOIN a_dmlk lk ON lk.id = ctct.lk INNER JOIN a_ct" + s_yy + "  ct ON ct.id = ctct.idct  LEFT JOIN";
			sql += " a_dmnhom muc ON ch.nhmuc = muc.id  LEFT JOIN a_dmchuong chuong ON chuong.id=ct.chuong  INNER JOIN a_dmnhombc bc ON bc.id = ct.idbc ";
			if (s_tuthang !="" || s_denthang!="")
				sql += " WHERE ct.thanggs BETWEEN "+ s_tuthang + " AND " + s_denthang;
			if (s_IDChuong!="") 
				sql += " AND ct.chuong=" + s_IDChuong;
			if (s_IDHoatdong!="") 
				sql += " AND ct.hoatdong=" + s_IDHoatdong;
			if (s_IDNguongoc!="") 
				sql += " AND ng.id=" + s_IDNguongoc;			
			if (s_IDlk!="") 
				sql += " AND ctct.lk=" + s_IDlk;
			if (s_idnhom!="") 
				sql += " AND ct.idbc=" + s_idnhom;
			sql += " AND (substr(trim(tk.stk),0,5)) like '66121%'" ;
			sql += " OR (substr(trim(tk.stk),0,5)) like '66122%' ";
			sql += " OR (substr(trim(tk.stk),0,5)) like '46121%'";
			//sql += " OR (substr(trim(tk.stk),0,5)) like '46122%'";			
			sql += " ORDER BY tk.stk ";
			sql += " ) t1 INNER JOIN ";
			sql += " (SELECT ch.mtm as muc, ch.ttk as noidungmuc FROM a_dmch ch where ch.cd=3 ORDER BY ch.mtm) t2 ON t1.muc=t2.muc";

			try
			{
				ds_Data = a.get_data(sql).Copy();
				if(ds_Data.Tables[0].Rows.Count<=0)
					flag_dsnull=true;
			}
			catch
			{
				flag_dsnull = true;
			}  
			#endregion
			
			#region them cot nsnn,cbnh,kpdh, kpca, mtqg,kp_treem, vienphi, dichvu ,thukhac, thangmay vao dataset
			if (flag_dsnull != true)
			{				
				int countRow=ds_Data.Tables[0].Rows.Count;				
				for(int j=0;j<countRow;j++)
				{		
					try
					{
						decimal sotien = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["sotien"].ToString());
						decimal nsnn = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["nsnn"].ToString());
						decimal cbnh = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["cbnh"].ToString());
						decimal kpdh = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["kpdh"].ToString());
						decimal kpca = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["kpca"].ToString());
						decimal mtqg = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["mtqg"].ToString());
						decimal kp_treem = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["kp_treem"].ToString());
						decimal vienphi = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["vienphi"].ToString());
						decimal dichvu = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["dichvu"].ToString());
						decimal thukhac = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["thukhac"].ToString());
						decimal thangmay = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["thangmay"].ToString());
						string manguon = (ds_Data.Tables[0].Rows[j]["manguon"].ToString());
						if (manguon=="0113")
						{
							nsnn += sotien;
							cbnh=0;
							kpdh = 0;
							kpca =0;
							mtqg=0;
							kp_treem=0;
							vienphi = 0;
							dichvu = 0;
							thukhac = 0;
							thangmay = 0;
						}
						else if (manguon=="02121")
						{	
							cbnh += sotien;
							nsnn = 0 ;
							kpdh = 0;
							kpca = 0;
							dichvu = 0;
							mtqg=0;
							kp_treem=0;
							vienphi=0;
							thukhac =0 ;
							thangmay = 0;
						}
						else if (manguon=="02122")
						{	
							kpdh += sotien;
							nsnn = 0 ;
							cbnh = 0;
							kpca = 0;
							dichvu = 0;
							mtqg=0;
							kp_treem=0;
							vienphi=0;
							thukhac =0 ;
							thangmay = 0;
						}
						else if (manguon=="02123")
						{	
							kpca += sotien;
							nsnn = 0 ;
							cbnh = 0;
							kpdh = 0;
							dichvu = 0;
							mtqg=0;
							kp_treem=0;
							vienphi=0;
							thukhac =0 ;
							thangmay = 0;
						}
						else if (manguon=="0214")
						{
							nsnn =0;
							cbnh = 0;
							kpca = 0;
							kpdh = 0;
							dichvu =0;
							mtqg += sotien;
							kp_treem=0;
							vienphi =0;
							thukhac = 0;
							thangmay= 0;
						}
						else if (manguon=="0218")
						{
							nsnn =0;
							cbnh = 0;
							kpdh = 0;
							kpca = 0;
							mtqg = 0 ;
							kp_treem += sotien;
							vienphi =0;
							dichvu = 0;
							thukhac = 0;
							thangmay= 0;
						}
						else if (manguon=="0401")
						{
							nsnn =0;
							cbnh = 0;
							kpdh = 0;
							kpca = 0;
							mtqg = 0 ;
							kp_treem =0;
							vienphi += sotien;
							dichvu =0;
							thukhac = 0;
							thangmay= 0;
						}
						else if (manguon == "0501")
						{
							nsnn =0;
							cbnh = 0;
							kpdh = 0;
							kpca = 0;
							mtqg = 0 ;
							kp_treem =0;
							dichvu += sotien;
							vienphi =0;
							thukhac = 0;
							thangmay= 0;
						}

						else if (manguon=="0402")
						{
							nsnn =0;
							cbnh = 0;
							kpdh = 0;
							kpca = 0;
							mtqg = 0 ;
							kp_treem = 0;
							vienphi =0;
							dichvu = 0;
							thukhac += sotien;
							thangmay= 0;
						}
						else if (manguon=="0502")
						{
							nsnn =0;
							cbnh = 0;
							kpdh = 0;
							kpca = 0;
							mtqg = 0 ;
							kp_treem = 0;
							vienphi =0;
							dichvu = 0;
							thukhac = 0;
							thangmay+= sotien;
						}
				
						ds_Data.Tables[0].Rows[j]["nsnn"] = nsnn;	
						ds_Data.Tables[0].Rows[j]["cbnh"] = cbnh;
						ds_Data.Tables[0].Rows[j]["kpdh"] = kpdh;
						ds_Data.Tables[0].Rows[j]["kpca"] = kpca;
						ds_Data.Tables[0].Rows[j]["mtqg"] = mtqg;	
						ds_Data.Tables[0].Rows[j]["kp_treem"] = kp_treem;
						ds_Data.Tables[0].Rows[j]["vienphi"] = vienphi;
						ds_Data.Tables[0].Rows[j]["dichvu"] = dichvu;
						ds_Data.Tables[0].Rows[j]["thukhac"] = thukhac;
						ds_Data.Tables[0].Rows[j]["thangmay"] = thangmay;					
					}
					catch (Exception Ex)
					{
						MessageBox.Show("Error : " + Ex ,"Thông báo !");
					}		
				}
			}
			ds_Data.AcceptChanges();
			#endregion												
			
			#region tao cac cot de group theo loai khoan 			
			if (flag_dsnull != true)
			{				
				int countRow1=ds_Data.Tables[0].Rows.Count;
				for(int j=0;j<countRow1;j++)
				{
					try
					{
						string group1 = (ds_Data.Tables[0].Rows[j]["group1"].ToString());
						string num_group1 = (ds_Data.Tables[0].Rows[j]["num_group1"].ToString());
						string group2 = (ds_Data.Tables[0].Rows[j]["group2"].ToString());
						string num_group2 = (ds_Data.Tables[0].Rows[j]["num_group2"].ToString());
						string stk = ((ds_Data.Tables[0].Rows[j]["stk"].ToString())).Trim().Split('.')[0].ToString();
						if (stk.StartsWith("661"))
						{
							group1="I - CHI HOẠT ĐỘNG";
							num_group1="1";
							if (stk.StartsWith("66121"))
							{
								group2="1. CHI THƯỜNG XUYÊN";
								num_group2="1.1";
							}
							if (stk.StartsWith("66122"))
							{
								group2="2. CHI KHÔNG THƯỜNG XUYÊN";
								num_group2="1.1";
							}
						}
						if (stk.StartsWith("662"))
						{
							group1="II - CHI DỰ ÁN";
							num_group1="2";
							if (stk.StartsWith("6621"))
							{
								group2="1. CHI QUẢN LÝ DỰ ÁN";
								num_group2="2.1";
							}
							if (stk.StartsWith("6622"))
							{
								group2="2. CHI THỰC HIỆN DỰ ÁN";
								num_group2="2.2";
							}
						}
						ds_Data.Tables[0].Rows[j]["group1"] = group1;
						ds_Data.Tables[0].Rows[j]["num_group1"] = num_group1;
						ds_Data.Tables[0].Rows[j]["group2"] = group2;
						ds_Data.Tables[0].Rows[j]["num_group2"] = num_group2;
						
					}
					catch (Exception Ex)
					{
						MessageBox.Show("Error : " + Ex ,"Thông báo !");
					}				
				}
			}
			ds_Data.AcceptChanges();
			//			ds_Data.WriteXml("..\\xml\\KT_t4.xml",XmlWriteMode.WriteSchema);
			#endregion

			#endregion
			
			#region DATASET2 ( 1 - denthang)			

			#region lay cac field bang cau query
			sql1 = " SELECT T1.*,T2.noidungmuc" ;
			sql1 += " FROM (";
			sql1 += " SELECT  DISTINCT ch.id as id,substr(trim(lk.lk),0,3) as loai,substr(trim(lk.lk),5,3) as khoan,lk.lk as loaikhoan,lk.tlk as tenloaikhoan,substr(trim(ch.mtm),0,4) ";
			sql1 += " as muc,substr(trim(ch.mtm),6,4) as tm, ng.mang as manguon,muc.nhom as nhom,tk.stk as stk,ch.ttk as noidungtm,ctct.stien ";
			sql1 += " as sotien,ct.thanggs as thang, 0 as nsnn,0 as cbnh, 0 as kpdh, 0 as kpca,0 as  mtqg,0 as kp_treem,0 as vienphi, 0 as dichvu ,0 as thukhac, 0 as thangmay,'' as group1,'' as num_group1,'' as group2,'' as ";
			sql1 += " num_group2 ,0 as lk_nsnn,0 as lk_cbnh, 0 as lk_kpdh, 0 as lk_kpca,0 as lk_mtqg, 0 as lk_treem, 0 as lk_vienphi,0 as lk_dichvu,0 as lk_thukhac, 0 as lk_thangmay, 1 as sapxep ";			
			sql1 += " FROM a_ctct" + s_yy + " ctct INNER JOIN a_dmtk tk ON tk.id=ctct.tkcoa OR tk.id=ctct.tknoa INNER JOIN a_dmch ch ON (ctct.mtmno = ch.id OR ctct.mtmco = ch.id) ";
			sql1 += " INNER JOIN a_dmng ng ON (substr(trim(tk.stk),7,length(ng.mang))=ng.mang) OR";
			sql1 += " (substr(trim(tk.stk),6,length(ng.mang))=ng.mang) LEFT JOIN a_dmlk lk ON lk.id = ctct.lk INNER JOIN a_ct" + s_yy + " ct ON ct.id = ctct.idct  LEFT JOIN";
			sql1 += " a_dmnhom muc ON ch.nhmuc = muc.id  LEFT JOIN a_dmchuong chuong ON chuong.id=ct.chuong  INNER JOIN a_dmnhombc bc ON bc.id = ct.idbc ";
			//				if (s_tuthang !="" || s_denthang!="")
			//					if (Convert.ToInt16(s_tuthang)==1)
			//					{
			sql1 += " WHERE ct.thanggs BETWEEN 1 AND " + s_denthang;				
			//					}
			//					else
			//					{
			//						sql1 += " WHERE ct.thanggs BETWEEN 1 AND " + (Convert.ToInt16(s_tuthang)-1);
			//					}
			if (s_IDChuong!="") 
				sql1 += " AND ct.chuong=" + s_IDChuong;
			if (s_IDHoatdong!="") 
				sql1 += " AND ct.hoatdong=" + s_IDHoatdong;
			if (s_IDNguongoc!="") 
				sql1 += " AND ng.id=" + s_IDNguongoc;			
			if (s_IDlk!="") 
				sql1 += " AND ctct.lk=" + s_IDlk;
			if (s_idnhom!="") 
				sql1 += " AND ct.idbc=" + s_idnhom;
			sql1 += " AND (substr(trim(tk.stk),0,5)) like '66121%'" ;
			sql1 += " OR (substr(trim(tk.stk),0,5)) like '66122%' ";
			sql1 += " OR (substr(trim(tk.stk),0,5)) like '46121%'";
			//sql1 += " OR (substr(trim(tk.stk),0,5)) like '46122%'";			
			sql1 += " ORDER BY tk.stk ";
			sql1 += " ) t1 INNER JOIN ";
			sql1 += " (SELECT ch.mtm as muc, ch.ttk as noidungmuc FROM a_dmch ch where ch.cd=3 ORDER BY ch.mtm) t2 ON t1.muc=t2.muc";

			try
			{
				ds_Data_ = a.get_data(sql1).Copy();
				if(ds_Data_.Tables[0].Rows.Count<=0)
					flag_dsnull=true;
			}
			catch
			{
				flag_dsnull = true;
			}  
		#endregion		

			#region them cot nsnn,cbnh,mtqg,kp_treem ,vienphi, thukhac, thangmay vao dataset
			if (flag_dsnull != true)
			{			
				decimal sotien=0,nsnn_=0,cbnh_=0, kpdh_ = 0, kpca_=0,mtqg_=0,kp_treem_=0,vienphi_ =0,dichvu_ =0,thukhac_=0,thangmay_ =0,nsnn1=0,cbnh1=0,mtqg1=0,kp_treem1=0, vienphi1=0, thukhac1=0, thangmay =0;
				string manguon="";
				int countRow=ds_Data_.Tables[0].Rows.Count;				
				//						int countRow1=ds_Data.Tables[0].Rows.Count;				
				for(int j=0;j<countRow;j++)
				{		
					try
					{
						sotien = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["sotien"].ToString());
						nsnn_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_nsnn"].ToString());
						cbnh_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_cbnh"].ToString());
						kpdh_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_kpdh"].ToString());
						kpca_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_kpca"].ToString());
						mtqg_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_mtqg"].ToString());
						kp_treem_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_treem"].ToString());
						vienphi_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_vienphi"].ToString());
						dichvu_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_dichvu"].ToString());
						thukhac_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_thukhac"].ToString());
						thangmay_ = Convert.ToDecimal(ds_Data_.Tables[0].Rows[j]["lk_thangmay"].ToString());
						manguon = (ds_Data_.Tables[0].Rows[j]["manguon"].ToString());
						if (manguon=="0113")
						{
							nsnn_ += sotien;
							cbnh_=0;
							kpdh_ = 0;
							kpca_ =0;
							mtqg_=0;
							kp_treem_=0;
							vienphi_ = 0;
							dichvu_ = 0;
							thukhac_ = 0;
							thangmay_ = 0;
						}
						else if (manguon=="02121")
						{	
							cbnh_ += sotien;
							nsnn_ = 0 ;
							kpdh_ = 0;
							kpca_ =0;
							mtqg_=0;
							kp_treem_=0;
							vienphi_=0;
							dichvu_ =0;
							thukhac_ =0 ;
							thangmay_ = 0;
						}
						else if (manguon=="02122")
						{	
							kpdh_ += sotien;
							nsnn_ = 0 ;
							cbnh_ = 0;
							kpca_ =0;
							mtqg_=0;
							kp_treem_=0;
							vienphi_=0;
							dichvu_ =0;
							thukhac_ =0 ;
							thangmay_ = 0;
						}
						else if (manguon=="02123")
						{	
							kpca_ += sotien;
							nsnn_ = 0 ;
							cbnh_ = 0;
							kpdh_ =0;
							mtqg_=0;
							kp_treem_=0;
							vienphi_=0;
							dichvu_ =0;
							thukhac_ =0 ;
							thangmay_ = 0;
						}
						else if (manguon=="0214")
						{
							nsnn_ =0;
							cbnh_ = 0;
							kpdh_ = 0;
							kpca_ =0;
							mtqg_ += sotien;
							kp_treem_=0;
							vienphi_ =0;
							dichvu_ =0;
							thukhac_ = 0;
							thangmay_= 0;
						}
						else if (manguon=="0218")
						{
							nsnn_ =0;
							cbnh_ = 0;
							kpdh_ = 0;
							kpca_ =0;
							mtqg_ = 0 ;
							kp_treem_ += sotien;
							vienphi_ =0;
							dichvu_ =0;
							thukhac_ = 0;
							thangmay_= 0;
						}
						else if (manguon=="0401")
						{
							nsnn_ =0;
							cbnh_ = 0;
							kpdh_ = 0;
							kpca_ =0;
							mtqg_ = 0 ;
							kp_treem_ =0;
							vienphi_ += sotien;
							dichvu_ =0;
							thukhac_ = 0;
							thangmay_= 0;
						}
						else if (manguon == "0501")
						{
							nsnn_ =0;
							cbnh_ = 0;
							kpdh_ = 0;
							kpca_ =0;
							mtqg_ = 0 ;
							kp_treem_ =0;
							dichvu_ += sotien;
							vienphi_ =0;
							thukhac_ = 0;
							thangmay_= 0;
						}

						else if (manguon=="0402")
						{
							nsnn_ =0;
							cbnh_ = 0;
							kpdh_ = 0;
							kpca_ =0;
							mtqg_ = 0 ;
							kp_treem_ = 0;
							vienphi_ =0;
							dichvu_=0;
							thukhac_ += sotien;
							thangmay_= 0;
						}
						else if (manguon=="0502")
						{
							nsnn_ =0;
							cbnh_ = 0;
							kpdh_ = 0;
							kpca_ =0;
							mtqg_ = 0 ;
							kp_treem_ = 0;
							vienphi_ =0;
							dichvu_=0;
							thukhac_ = 0;
							thangmay+= sotien;
						}
				
						ds_Data.Tables[0].Rows[j]["lk_nsnn"] = nsnn_;	
						ds_Data.Tables[0].Rows[j]["lk_cbnh"] = cbnh_;
						ds_Data.Tables[0].Rows[j]["lk_kpdh"] = kpdh_;
						ds_Data.Tables[0].Rows[j]["lk_kpca"] = kpca_;
						ds_Data.Tables[0].Rows[j]["lk_mtqg"] = mtqg_;
						ds_Data.Tables[0].Rows[j]["lk_treem"] = kp_treem_;
						ds_Data.Tables[0].Rows[j]["lk_vienphi"] = vienphi_;
						ds_Data.Tables[0].Rows[j]["dichvu"] = dichvu_;
						ds_Data.Tables[0].Rows[j]["lk_thukhac"] = thukhac_;
						ds_Data.Tables[0].Rows[j]["lk_thangmay"] = thangmay_;	
						
					}
					catch (Exception Ex)
					{
						MessageBox.Show("Error : " + Ex ,"Thông báo !");
					}		
				}

			}
			

			ds_Data_.AcceptChanges();

			
			#endregion												

			#region tao cac cot de group theo loai khoan 			
			if (flag_dsnull != true)
			{				
				int countRow1=ds_Data_.Tables[0].Rows.Count;
				for(int j=0;j<countRow1;j++)
				{
					try
					{
						string group1 = (ds_Data_.Tables[0].Rows[j]["group1"].ToString());
						string num_group1 = (ds_Data_.Tables[0].Rows[j]["num_group1"].ToString());
						string group2 = (ds_Data_.Tables[0].Rows[j]["group2"].ToString());
						string num_group2 = (ds_Data_.Tables[0].Rows[j]["num_group2"].ToString());
						string stk = ((ds_Data_.Tables[0].Rows[j]["stk"].ToString())).Trim().Split('.')[0].ToString();
						if (stk.StartsWith("661"))
						{
							group1="I - CHI HOẠT ĐỘNG";
							num_group1="1";
							if (stk.StartsWith ("66121") || (stk.StartsWith ("46121")))
							{
								group2="1. CHI THƯỜNG XUYÊN";
								num_group2="1.1";
							}
							
							if (stk.StartsWith("66122"))
							{
								group2="2. CHI KHÔNG THƯỜNG XUYÊN";
								num_group2="1.1";
							}
						}
						if (stk.StartsWith("662"))
						{
							group1="II - CHI DỰ ÁN";
							num_group1="2";
							if (stk.StartsWith("6621"))
							{
								group2="1. CHI QUẢN LÝ DỰ ÁN";
								num_group2="2.1";
							}
							if (stk.StartsWith("6622"))
							{
								group2="2. CHI THỰC HIỆN DỰ ÁN";
								num_group2="2.2";
							}
						}
						ds_Data_.Tables[0].Rows[j]["group1"] = group1;
						ds_Data_.Tables[0].Rows[j]["num_group1"] = num_group1;
						ds_Data_.Tables[0].Rows[j]["group2"] = group2;
						ds_Data_.Tables[0].Rows[j]["num_group2"] = num_group2;
					
					}
					catch {}		
				}
			}
			ds_Data_.AcceptChanges();

			
		#endregion

			try
			{
								
				if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
				else
				{							
					ds_Data.Merge(ds_Data_);
						
				}				
				
			}
			catch {}
			#endregion				

			if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
//			ds_Data.WriteXml("..\\xml\\KT_linh2.xml",XmlWriteMode.WriteSchema);
			if (flag_dsnull) return null;
			else return ds_Data;		
		}


		#endregion 
	}
}

